#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

void SortAges(int ages[], int length)
{
	if(ages == NULL || length == 0)
		cout << "No data to be sorted..." << endl;

	const int oldestAge = 99;
	int timesOfAge[oldestAge + 1];
	memset(timesOfAge,0,(oldestAge + 1)*sizeof(int));

	for(unsigned i = 0; i < length; i++)
	{
		if(ages[i] < 0 || ages[i] > oldestAge)
			cout << "Age is out of boundary..." << endl;

		int age = ages[i];
		timesOfAge[age]++;
	}

	int pos = 0;
	for(unsigned age = 1; age <= oldestAge; age++)
	{
		int times = timesOfAge[age];
		for(unsigned i = 0; i < times; i++)
			ages[pos++] = age;
	}
}

void PrintArray(const int array[], int length)
{
	for(unsigned i = 0; i < length; i++)
		cout << array[i] << " ";
}

int main(int argc, char** argv)
{
	int num,len;
	if(argc == 1)
	{
		cout << "Input num of data to sort..." << endl;
		cin >> num;
	}
	else
	{
		num = atoi(argv[1]);
	}
	
	len = num;
	
	int *ages = new int [num];
	if(ages == NULL)
	{
		cout << "Allocate memory failed..." << endl;
		return 0;
	}

	int i = 0;
	while(num)
	{
		cin >> ages[i++];
		num--;
	}
	
	PrintArray(ages,len);
	SortAges(ages,len);
	PrintArray(ages,len);

	delete [] ages;
	return 0;
}
